﻿#include "Widget.h"
#include "ui_Widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    setWindowTitle("商场收银系统");
    init();
}

Widget::~Widget()
{
    delete ui;
}

void Widget::init()
{
    ui->comboForm->addItems({"正常收费", "打8折", "满300返100"});
}


void Widget::on_btnReset_clicked()
{
    ui->spinPrice->setValue(0);
    ui->spinNum->setValue(0);
    ui->plainEdit->clear();
    ui->tol->setValue(0);
}

void Widget::on_btnOk_clicked()
{
    int money = ui->spinNum->value() * ui->spinPrice->value();

    cashContext* cash = new cashContext(ui->comboForm->currentIndex());

    int cur = cash->getResult(money);
    t += cur;
    ui->tol->setValue(t);
    ui->plainEdit->appendPlainText(QString("单价: ") + QString::number(ui->spinPrice->value()) +
                                   QString(" 数量： ") + QString::number(ui->spinNum->value()) +
                                   ui->comboForm->currentText() + QString(" 合计： ") +
                                   QString::number(cur));
}
